#ifndef COLLISIONSHAPETOOLS_H
#define COLLISIONSHAPETOOLS_H

#include <QObject>
class EditCollisionShapesView;
class ShapeManipulatorEngine;

class CollisionShapeTool : public QObject
{
    Q_OBJECT
public:
    explicit CollisionShapeTool(QWidget *view = 0);
    virtual ~CollisionShapeTool();

    virtual void enter() = 0;
    virtual void exit() = 0;

    virtual void mousePress(QMouseEvent* pEvent);
    virtual void mouseMove(QMouseEvent* pEvent);
    virtual void mouseRelease(QMouseEvent* pEvent);

    virtual void draw(QPainter& painter) const;

    static bool initTools(QWidget* view);
    static QPointer<CollisionShapeTool> toolByName(const QString& name);

    void transformToEditingViewCoordinates(QPointF &point);
protected:
    QPointer<EditCollisionShapesView> parentView() const;
    bool isInProgress() const;
    void setInProgress(bool b);
private:
    QString m_name;
    static QMap<QString, QPointer<CollisionShapeTool> > m_tools;
    bool m_bInProgress;
signals:
    void actionCanceled();
    void newObjectCreationStarted();
public slots:
    
};

class SelectCST : public CollisionShapeTool
{
    Q_OBJECT
public:
    SelectCST(QWidget* view);

    void enter();
    void exit();

    void draw(QPainter& painter) const;

    void mousePress(QMouseEvent* pEvent);
    void mouseMove(QMouseEvent* pEvent);
    void mouseRelease(QMouseEvent* pEvent);
private:
    QPointF m_origin;
    QRectF m_selectionRect;
};

class SelectAndManipulateCST : public CollisionShapeTool
{
    Q_OBJECT
public:
    SelectAndManipulateCST(QWidget* view);

    void enter();
    void exit();

    void draw(QPainter& painter) const;

    void mousePress(QMouseEvent* pEvent);
    void mouseMove(QMouseEvent* pEvent);
    void mouseRelease(QMouseEvent* pEvent);
private:
    boost::shared_ptr<ShapeManipulatorEngine> m_manipulatorEngine;
private slots:
    void enterManipulationMode();
    void exitManipulationMode();
};

class CreateCircleCST : public CollisionShapeTool
{
public:
    CreateCircleCST(QWidget* view);

    void enter();
    void exit();

    void mousePress(QMouseEvent* pEvent);
    void mouseMove(QMouseEvent* pEvent);
    void mouseRelease(QMouseEvent* pEvent);

    void draw(QPainter &painter) const;
private:
    QPointF m_center;
    float m_fRadius;
};

class CreateRectangleCST : public CollisionShapeTool
{
public:
    CreateRectangleCST(QWidget* view);

    void enter();
    void exit();

    void mousePress(QMouseEvent* pEvent);
    void mouseMove(QMouseEvent* pEvent);
    void mouseRelease(QMouseEvent* pEvent);

    void draw(QPainter &painter) const;
private:
    QRectF m_rect;
    QPointF m_origin;
};

class CreatePolyCST : public CollisionShapeTool
{
public:
    CreatePolyCST(QWidget* view);

    void enter();
    void exit();

    void mousePress(QMouseEvent* pEvent);
    void mouseMove(QMouseEvent* pEvent);
    void mouseRelease(QMouseEvent* pEvent);

    void draw(QPainter &painter) const;
private:
    QPolygonF m_poly;
    int m_nCurrentPoint;
};
#endif // COLLISIONSHAPETOOLS_H
